<div class="data-table table-striped">
    <form class="ids">
        <table>
            <thead>
            <tr>
                <th>ID</th>
                <th>车型</th>
                <th>年款</th>
                <th>生产状态</th>
                <th>销售状态</th>
                <th>厂商指导价(万元)</th>
                <th>变速箱类型</th>
                <th>排量</th>
                <th>状态</th>
                <th style="width:200px;text-align:center;">操作</th>
            </tr>
            </thead>
            <tbody id="trlist">
                <php>foreach($list AS $val):</php>
                <tr>
                    <td>{$val.model_id}</td>
                    <td style="float:left">{$val.name}</td>
                    <td>{$val.year}</td>
                    <td><php>echo C('CAR_MODEL_PRODUCE_STATUS.'.$val['produce_status']);</php></td>
                    <td><php>echo C('CAR_MODEL_SALE_STATUS.'.$val['sale_status']);</php></td>
                    <td>{$val.refer_price}</td>
                    <td><php>echo $val['gearbox']>0?C('GEARBOX.'.$val['gearbox']):'待查';</php></td>
                    <td>{$val.car_cc}</td>
                    <td id="status_cn{$val.model_id}"><if condition="$val['status'] eq 0">启用<else/>禁用</if></td>
                    <td style="width:200px;text-align:center;">
                        <if condition="$can_manage">
                            <php> if($val['status']>-1):</php>
                                <a title="编辑" href="/CarModel/model_add/id/{$val.model_id}" target="_blank">编辑</a>  &nbsp;
                                <if condition="$val['status'] gt 0">
                                    <a id="status{$val.model_id}" href="javascript:toggle('{$val.model_id}');">启用</a>  &nbsp;
                                <else/>
                                    <a id="status{$val.model_id}" href="javascript:toggle('{$val.model_id}');">禁用</a>  &nbsp;
                                </if>

                                <!--<a class="confirm ajax-get" href="javascript:del('{$val.model_id}');">删除</a>-->
                            <php>endif;</php>
                        </if>
                    </td>
                </tr>
                <php>endforeach;</php>
            </tbody>
        </table>
    </form>
</div>
<div class="pageFaye"><div class="pager">{$page}</div> <div class="clear"></div></div>
<input type="hidden" name="p" value="{$p}">
<input type="hidden" name="char" value="{$curr_char}">
<input type="hidden" name="model_id" value="">
<input type="hidden" name="enable" value="0">

<script>
    function toggle(id){
        var type = 1;
        if($('#status'+id).html()=='禁用'){
            type = 1;
        }else{
            type = 0;
        }
        $.post("/CarModel/toggle/",{'id':id,'table':'model','type':type}, function (data) {
            if(data.code=='200'){
                if($('#status'+id).html()=='禁用'){
                    $('#status'+id).html('启用')
                    $('#status_cn'+id).html('禁用')
                }else{
                    $('#status'+id).html('禁用')
                    $('#status_cn'+id).html('启用')
                }
            }else{
                shibai_alert(data.msg)
            }
        }, "json");
    }

    function del(id){
        confirm_alert('<div style="color:red">确认移除该车型？</div>', confirm);
        function confirm() {
            $('.determine').click(function () {
                colse_hide();
                remove(id);
            });
        }
    }

    function remove(id){
        $.post("/CarModel/remove/",{'id':id,'type':'model'}, function (data) {
            if(data.code=='200'){
                var curr_char = $('input[name=char]').val();
                btn_alert(data.msg,2,function(){
                    $(".fchar").each(function (i) {
                        if ($(this).text().trim() == curr_char) {
                            $(this).click();
                        }
                    });
                });
            }else{
                shibai_alert(data.msg);
            }
        }, "json");
    }

</script>